package com.example.speeddating.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.speeddating.entity.AutheticInfo;
import com.example.speeddating.enums.ResponseCodeEnum;
import com.example.speeddating.exception.CommonException;
import com.example.speeddating.mapper.AutheticInfoMapper;
import com.example.speeddating.service.AutheticInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author tina
 * @since 2023-06-28 11:14:33
 */
@Service
public class AutheticInfoServiceImpl extends ServiceImpl<AutheticInfoMapper, AutheticInfo> implements AutheticInfoService {

    @Autowired
    private AutheticInfoMapper autheticInfoMapper;


    @Transactional(rollbackFor = Exception.class)
    @Override
    public void autheticUser(AutheticInfo autheticInfo) {
        QueryWrapper<AutheticInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("card_id",autheticInfo.getCardId());
        AutheticInfo autheticInfo1 = autheticInfoMapper.selectOne(wrapper);
        if (autheticInfo1!=null){
            throw new CommonException(ResponseCodeEnum.CODE_601);
        }
        autheticInfoMapper.insert(autheticInfo);
    }

    @Override
    public AutheticInfo selectAutheticInfoById(Long userId) {
        QueryWrapper<AutheticInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id",userId);
        return autheticInfoMapper.selectOne(wrapper);
    }
}
